//
//  ViewController.swift
//  Swift-02
//
//  Created by xuPeng on 2017/8/3.
//  Copyright © 2017年 陈旭鹏. All rights reserved.
//

import UIKit
/// 屏幕高度
let kScreenHeight = UIScreen.main.bounds.size.height;
/// 屏幕宽度
let kScreenWidth = UIScreen.main.bounds.size.width;
class ViewController: UIViewController ,UITableViewDelegate,UITableViewDataSource{

    var tableView : UITableView!

    let StringdData = ["30 Days Swift"
        ,"企划部","软件部","咨询部","人事部","后勤部","产品部"]
    
    let pushBtn = UIButton()
    
    override func viewDidLoad() {
        super.viewDidLoad()
        //设置设置导航栏标题
        self.title="主页"
        //设置导航栏背景色
        self.navigationController?.navigationBar.barTintColor=UIColor.white

        let pushBarItem = UIBarButtonItem(title: "Push", style: .plain, target: self, action: #selector(backToPrevious))
        let leftBarBtn = UIBarButtonItem(title: "返回", style: .plain, target: self, action: #selector(backToPrevious))
        self.navigationItem.leftBarButtonItem = leftBarBtn
        self.navigationItem.rightBarButtonItem = pushBarItem
        
        //设置prompt属性,主要是用来做一些提醒，比如网络请求，数据加载等等
         self.navigationItem.prompt = "正在加载数据";
        //不用时，将prompt属性置为nil即可,自带动画效果哦
          self.navigationItem.prompt = nil;
        
        // 创建tableView
        creatTableView()
        
    }

    func backToPrevious(){
        let secondView = SecondViewController()
        self.navigationController?.pushViewController(secondView , animated: true)
        
    }
    func creatTableView(){
        tableView = UITableView.init(frame:CGRect(x:0.0,y:0.0,width:kScreenWidth,height:kScreenHeight-64),style:.plain)
        
        tableView.dataSource = self
        tableView.delegate = self
        
        //隐藏滚动条
        tableView.showsVerticalScrollIndicator = false
        tableView.showsHorizontalScrollIndicator = false
        self.view .addSubview(tableView)
    }
    
    //黄金三问
    func numberOfSections(in tableView: UITableView) -> Int {
        return 1
    }
    func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
        return StringdData.count
    }
    func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
        
        let identifier = "CELL"
        var cell = tableView.dequeueReusableCell(withIdentifier: identifier)
        if(cell == nil){
            cell=UITableViewCell(style: UITableViewCellStyle.value1, reuseIdentifier: identifier);
        }
        cell?.textLabel?.text = StringdData[indexPath.row];
        cell?.detailTextLabel?.text = "待添加内容";
        cell?.detailTextLabel?.font = UIFont .systemFont(ofSize: CGFloat(13))
        cell?.accessoryType=UITableViewCellAccessoryType.disclosureIndicator
        
        return cell!
        
    }
    
    //选中cell时触发这个代理
    open func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath){
         tableView.deselectRow(at: indexPath, animated: true)
        print("indexPath.row = SelectRow第\(indexPath.row)行")
    }

    
}

